<?php
	include 'php/config.php';
	session_start();
	if (!isset($_SESSION["id_utente"])) {
		header("Location: " . $ISSUER_HOST . "/login.php");
		exit();
	} else if (!$_SESSION["admin"]) {
		header("Location: " . $ISSUER_HOST . "/forbidden.html");
		exit();
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF8">
<script src="js/utils.js"></script>
<script src="js/remove_category.js"></script> 
<title>Remove Category</title>
</head>
<body>
<h1>Remove Category</h1>
	<div>
	<p>Da questa pagina è possibile rimuovere una categoria</p>
	</div>
	<?php
		// Connecting, selecting database
		$mysqli = new mysqli($MYSQL_HOST, $MYSQL_USERNAME, $MYSQL_PASSWORD, $MYSQL_DB_NAME);
		if ($mysqli->connect_errno) {
			echo "<p>Failed to connect to MySQL: " . $mysqli->connect_error . "<p>";
		} else {
			$query = "SELECT `nome`,`idCategoria` FROM `categoria`";
			$result = $mysqli->query($query);
			if (!$result) {
				echo "<p>Failed to run query " . $query . ": (" . $mysqli->errno . ") " .
						$mysqli->error . "<p>";
			}
		}
			
	?>
	<form action="php/scripts/remove_category.php" method="post" enctype="multipart/form-data">
	<div>
	<label>Rimuovi una categoria</label>
	</div>
		<label>Nome categoria</label>
		<select id="name" name="nome" onchange="validateRemoveCategoryForm()">
		<option value="">Scegli una categoria</option>
		<?php
			while ($row = $result->fetch_assoc()) {
    			echo "<option value=\"" . $row['idCategoria'] . "\">" . $row['nome'] . "</option>";    
			}
			mysqli_free_result($result);
			$mysqli->close();
		?>
		</select>
	<div id="message"></div>
	<input id="remove" type="submit" value="Rimuovi" disabled="disabled" />
	</form>
	<div>
	<p>Torna alla <a href="index.html">Home</a></p>
	</div>
</body>
</html>